;; doctest em Scheme, proposto por Guaracy Monteiro em
;; http://groups.google.com/group/eipc/msg/a33d261242226d21


;; ----------------------------------------------------
;; doctest Gambit V4.4.4
;;
(define (doctest f)
 (let ((sexp 0) (res 0) (test 0))
   (let loop ()
     (set! sexp (read f))
     (if (eof-object? sexp)
         (exit))
     (display sexp)
     (set! res (eval sexp))
     (if (equal? res (void))
         (newline)
         (begin
           (display " => ")
           (display res)
           (newline)
           (set! test (read f))
           (if (eof-object? sexp)
               (error "Fim inexperado do arquivo."))
           (display test)
           (if (equal? res (eval test))
               (display " <= OK")
               ;;(error "Valor informado não confere."))
               (display " <= ERRO"))
           (newline)
           ))
     (loop))))
;; ----------------------------------------------------

;; ----------------------------------------------------inicio
;;
(define s ";;;; inicio

10
10

(define (soma a b)
 (+ a b))

(soma 3 3) ;; 3+3=6

56

(define (fatorial n)
 (if (= n 1)
     1
     (* n (fatorial (- n 1)))))
(fatorial 5)
120


(fatorial 36)
371993326789901217467999448150835200000000


"
)
;; ----------------------------------------------------fim


(doctest (open-input-string s))